package com.youdianstar.app.entity

import com.google.gson.annotations.SerializedName
import com.youdianstar.app.common.util.CoordinateConverter

/**
 * File: SiteInfo
 * Description: 网点信息 - 新接口返回的数据结构
 */
data class SiteInfo(
    @SerializedName("id")
    val id: Int,
    
    @SerializedName("name")
    val name: String,
    
    @SerializedName("address")
    val address: String,
    
    @SerializedName("lat")
    val lat: Double,
    
    @SerializedName("lng")
    val lng: Double,
    
    @SerializedName("distance")
    val distance: Double,
    
    @SerializedName("open")
    val open: Boolean,
    
    @SerializedName("open_time")
    val openTime: String,
    
    @SerializedName("depotBorrow")
    val depotBorrow: Int,
    
    @SerializedName("depotEmpty")
    val depotEmpty: Int,
    
    @SerializedName("tel")
    val tel: String?,
    
    @SerializedName("borrow")
    val borrow: Boolean,
    
    @SerializedName("empty")
    val empty: Boolean,
    
    @SerializedName("powerbank_type")
    val powerbankType: Int
) {
    // 转换为BranchInfo
    fun toBranchInfo(): BranchInfo {
        // 后端返回的是BD09坐标，需要转换为GCJ02才能在Google Maps上正确显示
        val gcj02Coord = CoordinateConverter.bd09ToGcj02(lat, lng)
        android.util.Log.d("SiteInfo", "转换网点: name=$name, BD09($lat, $lng) -> GCJ02(${gcj02Coord.latitude}, ${gcj02Coord.longitude}), id=$id")
        return BranchInfo(
            id = id,
            branchName = name,  // 商家名称
            address = address,  // 地址
            addressMap = null,
            distance = distance,
            lat = gcj02Coord.latitude,  // 转换后的GCJ02纬度
            lng = gcj02Coord.longitude,  // 转换后的GCJ02经度
            logo = null,
            images = null,
            website = null,
            landlinePhone = tel,
            rent = depotBorrow,
            recovery = depotEmpty,
            isBusiness = open,
            openTime = openTime,
            billing = null
        )
    }
}

